package cn.maihe.elg.operation.institution.service;

import cn.maihe.elg.operation.model.dto.InnerBaseResp;
import cn.maihe.elg.operation.model.dto.institution.PushGuaranteeRespDTO;
import cn.maihe.elg.operation.model.enums.InnerRespCode;
import cn.maihe.elg.operation.service.facade.OrderInstitutionCallbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description 异步通知申请保函结果
 * @Author WJH
 * @Date 2021/04/27
 */
@Service
@Slf4j
public class ZhtGuarantorPushGuaranteeService {


    @Resource
    private OrderInstitutionCallbackService orderInstitutionCallbackService;


    public InnerBaseResp pushGuarantee(InnerBaseResp<PushGuaranteeRespDTO> innerBaseResp) {
        InnerBaseResp resp;
        if (innerBaseResp.getRespCode().isSuccess()) {
            //出函成功回调通知
            resp = orderInstitutionCallbackService.institutionPushGuarantee(innerBaseResp);
        } else {
            //出函失败回调通知
            resp = orderInstitutionCallbackService.institutionPushGuarantee(InnerBaseResp.of(InnerRespCode.FAILURE, innerBaseResp.getMessage(), innerBaseResp.getData()));
        }
        return resp;
    }

}
